package com.xyxeshang.es.music.backend.controller;


import com.xyxeshang.es.music.backend.entity.User;
import com.xyxeshang.es.music.backend.service.UserService;
import com.xyxeshang.es.music.backend.util.ResultUtil;
import org.apache.ibatis.jdbc.Null;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author xyx-Eshang
 */
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {

	@Resource
	UserService service;

	/**
	 * 保存用户信息
	 *
	 * @param userOpenId
	 * @param userNickName
	 * @param userAvatarUrl
	 * @return
	 */
	@GetMapping("/save")
	public ResultUtil<Null> save(String userOpenId, String userNickName, String userAvatarUrl) {
		return service.save(userOpenId, userNickName, userAvatarUrl);
	}

	/**
	 * 获取用户信息
	 *
	 * @param userOpenId
	 * @return
	 */
	@GetMapping("/get")
	public ResultUtil<User> get(String userOpenId) {
		return service.get(userOpenId);
	}

	/**
	 * 用code换取token和openId
	 *
	 * @param code
	 * @return
	 */
	@GetMapping("/getOpenId")
	public ResultUtil<Map<String, Object>> getOpenId(String code) {
		return service.getOpenId(code);
	}
}
